package com.sw.chinesewriteboard.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.blankj.utilcode.util.ToastUtils;
import com.bumptech.glide.Glide;
import com.sw.chinesewriteboard.R;

import java.io.File;

/**
 * 图像生产 图像裁剪
 */
public class DetailActivity extends AppCompatActivity {

    private ImageView ivResult;

    private String imagePath;

    public static void start(@NonNull Context context, @NonNull String imagePath) {
        Intent intent = new Intent(context, DetailActivity.class);
        intent.putExtra("image_path", imagePath);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);

        findViewById(R.id.detail_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });


        findViewById(R.id.detial_detele).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                File file = new File(imagePath);
                file.delete();
                new ToastUtils().setGravity(Gravity.CENTER, 0, 0).setMode(ToastUtils.MODE.LIGHT).show("删除成功~");
                finish();
            }
        });

        ivResult = findViewById(R.id.iv_result);

        imagePath = getIntent().getStringExtra("image_path");

        Glide.with(DetailActivity.this).load(imagePath).into(ivResult);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
